﻿/*
 * 由SharpDevelop创建。
 * 用户： Administrator
 * 日期: 2017/2/4
 * 时间: 20:21
 * 
 * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
 */
using System;

namespace MiniHttpServer
{
	class Program
	{
		public static void Main(string[] args)
		{
			Logger.WriteLog("{0} v{1} Program Start!", 
			                AppDomain.CurrentDomain.SetupInformation.ApplicationName, 
			                "1.0");
			
			var server = new Server();
			server.RemoteEnabled = true;
			server.Port = 90;
			server.WwwRootPath = ".";
			
			foreach (var arg in args)
			{
				if (arg.StartsWith("--port=", StringComparison.Ordinal)) {
					int port = 8080;
					int.TryParse(arg.Substring(7), out port);
					server.Port = port;
				} else if (arg.StartsWith("--rootpath=", StringComparison.Ordinal)) {
					server.WwwRootPath = arg.Substring(11);
				}
			}
			
			server.Start();
			
			Logger.WriteLog("[I]Http Server Running! Port: {0}", server.Port);
			
			while (true)
			{
				if (server.NeedStop)
				{
					server.Stop();
					break;
				}
				System.Threading.Thread.Sleep(1000);
			}
//			Console.ReadKey(true);
			Logger.WriteLog("Program Exit!");
		}
	}
}